/*
 * All rights Reserved, Copyright (C) WANGJIAN LIMITED 2019
 * FileName: PasswordUtil.java
 * Version:  $Revision$
 * Modify record:
 * NO. |     Date       |    Name         |      Content
 * 1   | 2019年10月17日        |  wangjian    | original version
 */
package com.pl.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * class name:PasswordUtil <BR>
 * class description: 密码工具 <BR>
 * Remark: <BR>
 * @version 1.00 2019年10月17日
 * @author wangjian
 */
public class PasswordUtil {
	
	private static BCryptPasswordEncoder encode = new BCryptPasswordEncoder();
	
	/**
	 * 
	 * Method name: matches <BR>
	 * Description: 判断密码是否正确 <BR>
	 * Remark: <BR>
	 * @return  boolean<BR>
	 * @date 2019年10月17日
	 * @author wangjian
	 */
	public static boolean matches(String dbPassword, String inputPassword) {

		return encode.matches(inputPassword, dbPassword);
	}
	
	/**
	 * 获得加密后的密码
	 */
	public static String getEncoderPassword(String password) {
		String newPassword = encode.encode(password);
		return newPassword;
	}
	
	public static void main(String[] args) {
		
		String password = "123456";
		
		String e1 = "$2a$10$86reeOWyB/K/grLDKtsBjOeU1nuODWOuyDfrtPi4xkEigR7lpJkkG";
		String e2 = "$2a$10$rlcBDIOb5azIpoWN4XrD8OUZekiVqidO1rNAEkfjM3IT2.w79fmye";
		
		System.out.println(getEncoderPassword(password));
		System.out.println(matches(e1, password));
		System.out.println(matches(e2, password));
	}
}
